const http = require('http');
const fs = require('fs');
const server = http.createServer((request,response) => {
    //获得路径
    let {pathname} = new URL(request.url,'http://localhost:9000');
    if (pathname == '/') {
        let html = fs.readFileSync('./index.html');
        response.end(html);
    } else if (pathname == '/css/index.css') {
        let css= fs.readFileSync('./css/index.css');
        response.end(css);
    } else if (pathname == '/js/index.js' ) {
        let js = fs.readFileSync('./js/index.js');
        response.end(js);
    } else {
        response.statusCode = 404;
        response.end("<h1>404 Not Found</h1>");
    }
});

server.listen(9000,() => {
    console.log('服务已经启动 9000端口已经启动....')
});